package com.my.cloud.controller;

import cn.hutool.core.date.DateUtil;
import com.my.cloud.apis.PayFeignApi;
import com.my.cloud.entities.PayDTO;
import com.my.cloud.resp.ResultData;
import com.my.cloud.resp.ReturnCodeEnum;
import jakarta.annotation.Resource;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * @author zhupanlin
 * @version 1.0
 * @description: TODO
 * @date 2024/3/7 19:33
 */
@RestController
@RequestMapping("/consumer/feign/pay")
public class OrderController {
    
    // 通过调用feign接口直接调用服务
    @Resource
    private PayFeignApi payFeignApi;
    
    @PostMapping("add")
    public ResultData addOrder(@RequestBody PayDTO payDTO){
        ResultData resultData = payFeignApi.addPay(payDTO);
        return resultData;
    }
    
    @GetMapping("/get/{id}")
    public ResultData getPayInfo(@PathVariable("id") Integer id){
        ResultData resultData = null;
        try {
            System.out.println("-------调用开始" + DateUtil.now());
            resultData = payFeignApi.getPayInfo(id);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("-------调用结束" + DateUtil.now());
            return ResultData.failure(ReturnCodeEnum.RC500.getCode(), e.getMessage());
        }
        return resultData;
    }
    
    @GetMapping("/get/info")
    public String mylb(){
        return payFeignApi.mylb();
    }
    
    
}
